home *** CD-ROM | disk | FTP | other *** search
- Path: news.itd.umich.edu!not-for-mail
- From: jlthomas@umd.umich.edu (Jeffrey L. Thomas)
- Newsgroups: comp.lang.c
- Subject: Re: Writing to a port
- Date: 31 Jan 1996 12:19:21 -0500
- Organization: Univerisity of Michigan - Dearborn
- Message-ID: <4eo8ap$3vk@null.umd.umich.edu>
- References: <22898@storm.LakeheadU.Ca>
- NNTP-Posting-Host: null.umd.umich.edu
- NNTP-Posting-User: jlthomas
- X-Newsreader: NN version 6.5.0 #3 (NOV)
-
- romulus@lakeheadu.ca (Romulus the Almighty) writes:
-
- >Help would be greatly appreciated with the following:
-
- >I am attempting to make a cgi C program that will telnet to port 25 on
- >a server, take an argument to who the sender is, and take the rest of the
- >argument and send it to the recipient directly using sendmail on port 25
- >of a server. I use system(); to telnet over to the port and here is where
- >my problem is: How do I send statements directly to the port such as
- >"HELO flash.lakeheadu.ca" and the other necessary statements...
-
- >Thanx
-
- > John
-
- you don't there is know way of comunicating with the system() fuction aside
- from the parameters you pass it.
-
- here is what you want to do
-
- void open25(host)
- char host[];
- {
- int pdc[2], pdp[2];
-
- if (pipe(pdc)<0 || pipe(pdp)<0) { perror("pipe"); exit(1); }
-
- if ((pid= fork())<0) { perror("fork"); exit(1); }
-
- if (pid==0) { /* I am Child */
- dup2(pdc[0],0);
- dup2(pdp[1],1);
-
- execl("/usr/ucb/telnet","telnet",host,"25");
- perror("exec: telnet");
- exit(1);
- }
-
- /* I am Parent */
-
- dup2(pdc[1],1);
- dup2(pdp[0],0);
- }
-
- and in you main program
-
- open25("mailhost"); /* or whatever machine */
-
- printf("HELO flash.lakeheadu.ca"); /* blah, blah, blah */
- gets(line) /* getting the response back from the telnet */
-
- and your off and running.
-
- but you don't even want to do that what you really want to do is to learn
- all about sockets and to this with the socketing calls.
-
-
- Have a great day.
- Jeff
- --
- \|||/ _Spike_Man_ ____ | Jeffery L. Thomas | "The important thing is
- ^.^ The Internet's / \ | jlthomas@umich.edu | not to stop questioning.
- v first superhero \ SM / | "This time it will | Curiosity has it own
- "more than a cute .sig" \__/ | surely run" - anon | reason for existing."
-